﻿#pragma once

#include <cstdlib>
#include <tuple>

struct Step
{
    int u, v;

    bool operator==(const Step &other) const
    {
        return u == other.u && v == other.v;
    }

    Step operator+(const Step &other) const
    {
        return {u + other.u, v + other.v};
    }

    Step operator-(const Step &other) const
    {
        return {u - other.u, v - other.v};
    }

    Step operator*(int k) const
    {
        return {u * k, v * k};
    }

    Step operator-() const
    {
        return {-u, -v};
    }

    int modulus() const
    {
        return std::max(std::abs(u), std::abs(v));
    }

    Step normalized() const
    {
        int l = modulus();
        return {u / l, v / l};
    }

    Step rotated() const
    {
        return {-v, u};
    }

    void normalize()
    {
        int l = modulus();
        u /= l;
        v /= l;
    }

    void rotate()
    {
        int temp = u;
        u = -v;
        v = temp;
    }

    operator std::tuple<int, int>() const
    {
        return std::make_tuple(u, v);
    }
};